#ifndef __UTIL_H__
#define __UTIL_H__
#include "JTVRecInterface.h"

#include <afxwin.h>
#include <afx.h>


// convert from DetectRectangle to CRect
CRect Convert2CRect(const DetectRectangle& rect)
{
    return CRect(rect.x, rect.y, rect.x+rect.width, rect.y+rect.height);
}

// convert from CRect to DetectRectangle
DetectRectangle Convert2DRect(const CRect& rect)
{
    DetectRectangle drect = {rect.left, rect.top, rect.Width(), rect.Height()};
    return drect;
}


// auto convertor
class GeneralRect : public DetectRectangle
{
public:
    GeneralRect(const DetectRectangle& rect)
    {
        memcpy(this, &rect, sizeof(DetectRectangle));
    }

    GeneralRect(const CRect& crect)
    {
        x = crect.left;
        y = crect.top;
        width = crect.right - crect.left;
        height = crect.bottom - crect.top;
    }

    GeneralRect(int x, int y, int width, int height)
    {
        this->x = x;
        this->y = y;
        this->width = width;
        this->height = height;
    }

    operator CRect()
    {
        return CRect(x, y, x+width, y+height);
    }

    operator DetectRectangle()
    {
        return *((DetectRectangle*)this);
    }

};

//
// example
//
// CRect crect(0,0,5,5);
// DetectRectangle drect = {1,1,3,3};
// 
// // convert from DetectRectangle to CRect
// CRect crect2 = GeneralRect(drect);
// // convert from CRect to DetectRectangle
// DetectRectangle drect2 = GeneralRect(crect);

#endif // __UTIL_H__
